//
//  JokeTableViewCell.m
//  ITHome
//
//  Created by lanou3g on 15/7/15.
//  Copyright (c) 2015年 YAX. All rights reserved.
//

#import "JokeTableViewCell.h"

@implementation JokeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //顶图片
        self.upImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth/4 - 20, 5, 10, 10)];
        self.upImageView.image = [UIImage imageNamed:@"icon_for_active"];
        [self.contentView addSubview:_upImageView];
        //踩图片
        self.downImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth/4*3 - 20 , 5, 10, 10)];
        self.downImageView.image = [UIImage imageNamed:@"icon_against_active"];
        [self.contentView addSubview:_downImageView];
        
        //顶人数
        self.upLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/4, 5, 40, 10)];
        self.upLabel.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.upLabel.text = @"1232";
        self.upLabel.font = [UIFont systemFontOfSize:9];
        [self.contentView addSubview:_upLabel];
        
        //踩人数
        self.downLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/4*3, 5, 40, 10)];
        self.downLabel.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.downLabel.text = @"12";
        self.downLabel.font = [UIFont systemFontOfSize:9];
        [self.contentView addSubview:_downLabel];
        
        //内容
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.textColor = [UIColor blackColor];
        self.contentLabel.numberOfLines = 0;
        self.contentLabel.text = @"发大水了疯啦放大镜发氨分解大量守空房姐大饭店接撒发觉范德萨副科级多少啦肯德基啊发了多少骄傲拉德斯基林风；都是风景；按时缴费单撒雷克萨解放路；打啊解放东路；撒解放东路；撒发";
        self.contentLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_contentLabel];
        
        //分享图片
        self.shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.shareButton setBackgroundImage:[UIImage imageNamed:@"icon_share"] forState:UIControlStateNormal];
        [self.contentView addSubview:_shareButton];
        
        //作者
        self.autherLabel = [[UILabel alloc] init];
        self.autherLabel.font = [UIFont systemFontOfSize:11];
        self.autherLabel.textAlignment = NSTextAlignmentRight;
        self.autherLabel.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:140/255.0 alpha:1];
        self.autherLabel.text = @"作者：airende";
        [self.contentView addSubview:_autherLabel];
    }
    return self;
}

- (void)cellSetModel:(JokeModel *)model
{
    self.contentLabel.text = model.content;
    //自适应高度。
    CGRect bounds = [self heightForCell:model];
    self.contentLabel.frame = CGRectMake(20, 20, kScreenWidth - 40,bounds.size.height);
    
    self.shareButton.frame = CGRectMake(kScreenWidth/4 - 20,_contentLabel.frame.size.height + _contentLabel.frame.origin.y, 20, 20);
    self.autherLabel.frame = CGRectMake(kScreenWidth / 4 * 1.6, _contentLabel.frame.size.height + _contentLabel.frame.origin.y, kScreenWidth/2, 20);
    self.upLabel.text = [NSString stringWithFormat:@"%ld",model.up];
    self.downLabel.text = [NSString stringWithFormat:@"%ld",-model.down];
    self.autherLabel.text = [NSString stringWithFormat:@"作者：%@",model.login];
}

//自适应cell高度方法。
- (CGRect)heightForCell:(JokeModel *)model
{
   CGRect bounds = [model.content boundingRectWithSize:CGSizeMake(280, 5000) options:NSStringDrawingUsesLineFragmentOrigin  attributes: [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15]forKey:NSFontAttributeName]context:nil];
    
    return bounds;
}

- (void)awakeFromNib {
    // Initialization code
}



@end
